/*
 * @Author: 许警 11378748333@
 * @Date: 2024-03-22 14:16:48
 * @LastEditors: 许警 11378748333@
 * @LastEditTime: 2024-03-22 14:46:40
 * @FilePath: /hsxlsystem/src/hooks/usePagination.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// usePagination.js
import { reactive, computed } from 'vue'
// 优先使用useTable吧
export default function usePagination(initialCurrent = 1, initialPageSize = 10, initialTotal = 0) {
  // 使用 reactive 创建响应式分页状态对象
  const pagination = reactive({
    current: initialCurrent,
    pageSize: initialPageSize,
    total: initialTotal,
    pageSizeOptions: ['10', '20', '30'],
    showTotal: (total, range) => {
      return '共' + total + '条'
    },
    showQuickJumper: true,
    showSizeChanger: true
  })

  // 方法，用于更新当前页码
  function setCurrentPage(page) {
    pagination.current = page
  }

  // 方法，用于更新每页显示的条目数
  function setPageSize(size) {
    pagination.pageSize = size
  }

  function setTotal(size) {
    pagination.pageSize = size
  }

  // 返回分页状态和方法
  return {
    pagination,
    setCurrentPage,
    setPageSize,
    setTotal
  }
}
